<template>
  <van-button type="primary">主要按钮</van-button>
  <div class="wrap">人脸识别页面</div>
  <button @click="takePhoto">拍照</button>
</template>

<script setup>
import { onMounted, reactive, toRefs, ref } from 'vue'

import { postData } from '@/request/request.js'
import { useRoute, useRouter } from 'vue-router'
let router = useRouter()
let route = useRoute()
let query = route.query
localStorage.setItem('user_id', query.user_id)
localStorage.setItem('access_token', query.access_token)
localStorage.setItem('open_id', query.open_id)
localStorage.setItem('currentPath', query.currentPath)

let msg = ref('')

let init = () => {
  // uni.authorize({
  //   scope: 'scope.camera',
  //   success() {
  //     console.log('授权了摄像头')
  //   },
  // })
  console.log('11111', uni)
  console.log('2222', uni.createCameraContext())
}

let takePhoto = () => {
  // console.log(navigator.mediaDevices)
  // console.log(uni)
  // console.log(uni.navigator)
  //  uni.authorize({
  //     scope: 'scope.camera',
  //     success() {
  //       console.log('授权了摄像头')
  //     },
  //   })
  // const cameraContext = uni.createCameraContext()
  // cameraContext.takePhoto({
  //   quality: 'high',
  //   success: (res) => {
  //     console.log('拍照成功', res.tempImagePath)
  //   },
  //   fail: (err) => {
  //     console.error('拍照失败', err)
  //   },
  // })
  wx.chooseImage({
    count: 1,
    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
    sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
    success: (imgRes) => {
      console.log('3333', imgRes)
    },
    fail: (err) => {
      console.log(err)
    },
  })
  // if (uni.createCameraContext) {
  //   this.cameraContext = uni.createCameraContext() //因为pc上不是微信浏览器没法打印 所以很麻烦
  //   console.log(this.cameraContext)
  //   msg.value = JSON.stringify(this.cameraContext)
  // } else {
  //   console.log(2) //现在直接进入这了
  //   msg.value = 'hhh'
  // }
}

onMounted(() => {
  init()
})
</script>

<style scoped></style>
